import { INCREMENT_COUNT, INCREMENT_N_COUNT } from "../mutation-types";

const state = {
  count: 0,
  price: 100,
  num: 0,
};
const mutations = {
  [INCREMENT_COUNT](state) {
    state.count++;
  },
  [INCREMENT_N_COUNT](state, { n }) {
    state.count += n;
  },
};
const actions = {
  incrementWait(store) {
    setTimeout(() => {
      store.commit(INCREMENT_COUNT);
    }, 2000);
  },
  incrementNWait(store, payload) {
    setTimeout(() => {
      store.commit(INCREMENT_N_COUNT, payload);
    }, 2000);
  },
};
const getters = {
  allPrice(state) {
    return state.count * state.price;
  },
};

export default {
  //开启命名空间
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
